package com.compiler.lexico.token;

import com.compiler.logger.Logger;
import com.compiler.syntactic.ParserVal;

public class Token {
	private String data;
	private String type;
	private long line;
	private int yylex;
	
	public Token() {
		this.data = new String();
		this.line = 1;
	}
	
	public Token(String data, String type, long line, int yylex) {
		this.data = data;
		this.type = type;
		this.line = line;
		this.yylex = yylex;
	}
	
	public void addChar(char c) {
		this.data += c;
	}
	
	public void clean() {
		this.data = "";
	}
	
	public String getData() {
		return this.data;
	}
	
	public long getLine() {
		return this.line;
	}
	
	public String getType() {
		return type;
	}
	
	public String toString() {
		return this.data;
	}
	
	public void lineIncr() {
		this.line += 1;
	}
	
	public int getSize() {
		return this.data.length();
	}
	
	public void setType(String type) {
		this.type = type;
	}

	public Token clone() {
		Token t = new Token();
		t.data = this.data;
		t.line = this.line;
		t.type = this.type;
		return t;
	}
	
	public void truncate() {
		this.data = this.data.substring(0, 16);
		Logger.getInstance().log("LEXICO", Logger.WARNINGLevel, "Linea #"+this.line+" ---> Identificador largo, se trunca a 16 caracteres","LEXICO");
	}
	
	public void setYylex(int yylex) {
		this.yylex = yylex;
	}
	
	public int yylex() {
		return this.yylex;
	}
	
	public ParserVal getParserVal() {
		return new ParserVal(this.data);
	}

	@Override
	public int hashCode() {
		return this.data.hashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		return(((Token)obj).data.equals(this.data));
	}

}
